#pragma once


class smsd{
public:
	char		name[32];
	int			fieldSize;
	const char*	fmt;
	smsd(){};
	virtual void	defaultValue(void* to){
	}
	void* parse(char*	from,void*	to){
		if(*from)
			sscanf_s(from,fmt,to);
		else
			defaultValue(to);
		return (void*)(((char*)to)+fieldSize);
	}
};

typedef char str32[32];

class sstr32	: public smsd{
public:
	virtual void	defaultValue(void* to){
		((char*)to)[0]=0;
	}
	sstr32(char*	fn){
		strcpy_s(name,32,fn);
		fmt="%s";
		fieldSize=sizeof(char[32]);
	}
	virtual ~sstr32(){};
};

class sf32	: public smsd{
public:
	virtual void	defaultValue(void* to){
		((float*)to)[0]=0.0f;
	}
	sf32(char*	fn){
		strcpy_s(name,32,fn);
		fmt="%f";
		fieldSize=sizeof(float);
	}
	virtual ~sf32(){};
};

class si32	: public smsd{
public:
	virtual void	defaultValue(void* to){
		((int*)to)[0]=0;
	}
	si32(char*	fn){
		strcpy_s(name,32,fn);
		fmt="%d";
		fieldSize=sizeof(int);
	}
	virtual ~si32(){};
};


smsd*	starEntryDef[];

typedef struct{
	int	StarID;
	int	HIP;
	int	HD;
	int	HR;
	str32	Gliese;
	str32	BayerFlamsteed;
	str32	ProperName;
	float	RA;
	float	Dec;
	float	Distance;
	float	PMRA;
	float	PMDec;
	float	RV;
	float	Mag;
	float	AbsMag;
	str32	Spectrum;
	float	ColorIndex;
	float	X;
	float	Y;
	float	Z;
	float	VX;
	float	VY;
	float	VZ;
}starEntry;


void*	loadFile(char*	fname,int*	outSize);
void*	loadCSVdata(char*	fname,smsd**	fields,int	fieldCount,int entrySize,int*	outElemCount);

